<template>
  <div class="app-container">
    <div class="search-container">
      <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
        <el-form-item label="门诊号" prop="clinicNo">
          <el-input
            v-model="queryParams.clinicNo"
            clearable
            placeholder="请输入门诊号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="住院号" prop="visitNo">
          <el-input
            v-model="queryParams.visitNo"
            clearable
            placeholder="请输入住院号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="结算号" prop="rcptNo">
          <el-input
            v-model="queryParams.rcptNo"
            clearable
            placeholder="请输入结算号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单号" prop="documentNo">
          <el-input
            v-model="queryParams.documentNo"
            clearable
            placeholder="请输入单号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="明细id" prop="detailId">
          <el-input
            v-model="queryParams.detailId"
            clearable
            placeholder="请输入明细id"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="退药明细id" prop="detailRefundId">
          <el-input
            v-model="queryParams.detailRefundId"
            clearable
            placeholder="请输入退药明细id"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用"
                      prop="recordType">
          <el-select v-model="queryParams.recordType"
                     clearable
                     placeholder="请选择1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用">
            <el-option
              v-for="dict in dictDataMap['${dictType}']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="来源类型" prop="sourceType">
          <el-select v-model="queryParams.sourceType" clearable placeholder="请选择来源类型">
            <el-option
              v-for="dict in dictDataMap['${dictType}']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品ID" prop="infoId">
          <el-input
            v-model="queryParams.infoId"
            clearable
            placeholder="请输入消耗品ID"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品库存表id" prop="stockId">
          <el-input
            v-model="queryParams.stockId"
            clearable
            placeholder="请输入消耗品库存表id"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品产品类别" prop="materialStyle">
          <el-select v-model="queryParams.materialStyle" clearable placeholder="请选择消耗品产品类别">
            <el-option
              v-for="dict in dictDataMap['material_style']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品产品类别名称" prop="materialStyleName">
          <el-input
            v-model="queryParams.materialStyleName"
            clearable
            placeholder="请输入消耗品产品类别名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品分类" prop="materialClass">
          <el-select v-model="queryParams.materialClass" clearable placeholder="请选择消耗品分类">
            <el-option
              v-for="dict in dictDataMap['bill_item_class_dict']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品分类名称" prop="materialClassName">
          <el-input
            v-model="queryParams.materialClassName"
            clearable
            placeholder="请输入消耗品分类名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品名称" prop="materialName">
          <el-input
            v-model="queryParams.materialName"
            clearable
            placeholder="请输入消耗品名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品机构编码" prop="materialCode">
          <el-input
            v-model="queryParams.materialCode"
            clearable
            placeholder="请输入消耗品机构编码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品系统编码" prop="sysMaterialCode">
          <el-input
            v-model="queryParams.sysMaterialCode"
            clearable
            placeholder="请输入消耗品系统编码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="消耗品拼音码" prop="materialInput">
          <el-input
            v-model="queryParams.materialInput"
            clearable
            placeholder="请输入消耗品拼音码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="规格" prop="spec">
          <el-input
            v-model="queryParams.spec"
            clearable
            placeholder="请输入规格"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单位" prop="units">
          <el-select v-model="queryParams.units" clearable placeholder="请选择单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="单位名称" prop="unitsName">
          <el-input
            v-model="queryParams.unitsName"
            clearable
            placeholder="请输入单位名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="批号" prop="batchNo">
          <el-input
            v-model="queryParams.batchNo"
            clearable
            placeholder="请输入批号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="生产日期" prop="produceDate">
          <el-date-picker v-model="queryParams.produceDate"
                          clearable
                          placeholder="请选择生产日期"
                          type="date"
                          value-format="YYYY-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-date-picker v-model="queryParams.expireDate"
                          clearable
                          placeholder="请选择有效期"
                          type="date"
                          value-format="YYYY-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="厂商名称" prop="firmName">
          <el-input
            v-model="queryParams.firmName"
            clearable
            placeholder="请输入厂商名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="包装数量" prop="packageNum">
          <el-input
            v-model="queryParams.packageNum"
            clearable
            placeholder="请输入包装数量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="价表" prop="priceId">
          <el-input
            v-model="queryParams.priceId"
            clearable
            placeholder="请输入价表"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="大小包装" prop="packSize">
          <el-input
            v-model="queryParams.packSize"
            clearable
            placeholder="请输入大小包装"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="数量" prop="amount">
          <el-input
            v-model="queryParams.amount"
            clearable
            placeholder="请输入数量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="现行数量" prop="currentAmount">
          <el-input
            v-model="queryParams.currentAmount"
            clearable
            placeholder="请输入现行数量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="进货价" prop="tradePrice">
          <el-input
            v-model="queryParams.tradePrice"
            clearable
            placeholder="请输入进货价"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单价" prop="itemPrice">
          <el-input
            v-model="queryParams.itemPrice"
            clearable
            placeholder="请输入单价"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="总额" prop="costs">
          <el-input
            v-model="queryParams.costs"
            clearable
            placeholder="请输入总额"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="收费系数" prop="priceQuotiety">
          <el-input
            v-model="queryParams.priceQuotiety"
            clearable
            placeholder="请输入收费系数"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="开单医生" prop="orderDoctor">
          <el-input
            v-model="queryParams.orderDoctor"
            clearable
            placeholder="请输入开单医生"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="申请科室(领取科室)" prop="applyDept">
          <el-input
            v-model="queryParams.applyDept"
            clearable
            placeholder="请输入申请科室(领取科室)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="申请人(领取人)" prop="applyPerson">
          <el-input
            v-model="queryParams.applyPerson"
            clearable
            placeholder="请输入申请人(领取人)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="记录科室(发放科室)" prop="recordDept">
          <el-input
            v-model="queryParams.recordDept"
            clearable
            placeholder="请输入记录科室(发放科室)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="记录人(发放人)" prop="recordPerson">
          <el-input
            v-model="queryParams.recordPerson"
            clearable
            placeholder="请输入记录人(发放人)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="领用人" prop="usePerson">
          <el-input
            v-model="queryParams.usePerson"
            clearable
            placeholder="请输入领用人"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="机构ID" prop="orgId">
          <el-input
            v-model="queryParams.orgId"
            clearable
            placeholder="请输入机构ID"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="机构名称" prop="orgName">
          <el-input
            v-model="queryParams.orgName"
            clearable
            placeholder="请输入机构名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="更新人名称" prop="updateByName">
          <el-input
            v-model="queryParams.updateByName"
            clearable
            placeholder="请输入更新人名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input
            v-model="queryParams.remarks"
            clearable
            placeholder="请输入备注"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['material:materialStockAllLog:add']"
          plain
          type="primary"
          @click="handleAdd"
        >
          <template
            #icon>
            <i-ep-plus/>
          </template>
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['material:materialStockAllLog:edit']"
          :disabled="single"
          plain
          type="success"
          @click="handleUpdate"
        >
          <template #icon>
            <i-ep-edit/>
          </template>
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['material:materialStockAllLog:remove']"
          :disabled="multiple"
          plain
          type="danger"
          @click="handleDelete"
        >
          <template #icon>
            <i-ep-delete/>
          </template>
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['material:materialStockAllLog:export']"
          plain
          type="warning"
          @click="handleExport"
        >
          <template #icon>
            <i-ep-download/>
          </template>
          导出
        </el-button>
      </el-col>
    </el-row>

    <el-table v-adaptive :border="true" :data="materialStockAllLogList" :header-cell-style="$headerCellStyle"
              :stripe="true" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column :align="'center'" type="selection" width="55"/>
      <el-table-column v-if="true" :align="'center'" label="主键" prop="allLogId"/>
      <el-table-column :align="'center'" label="门诊号" prop="clinicNo"/>
      <el-table-column :align="'center'" label="住院号" prop="visitNo"/>
      <el-table-column :align="'center'" label="结算号" prop="rcptNo"/>
      <el-table-column :align="'center'" label="单号" prop="documentNo"/>
      <el-table-column :align="'center'" label="明细id" prop="detailId"/>
      <el-table-column :align="'center'" label="退药明细id" prop="detailRefundId"/>
      <el-table-column :align="'center'"
                       label="1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用" prop="recordType"/>
      <el-table-column :align="'center'" label="来源类型" prop="sourceType"/>
      <el-table-column :align="'center'" label="消耗品ID" prop="infoId"/>
      <el-table-column :align="'center'" label="消耗品库存表id" prop="stockId"/>
      <el-table-column :align="'center'" label="消耗品产品类别" prop="materialStyle">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['material_style']" :value="scope.row.materialStyle"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="消耗品产品类别名称" prop="materialStyleName"/>
      <el-table-column :align="'center'" label="消耗品分类" prop="materialClass">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['bill_item_class_dict']" :value="scope.row.materialClass"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="消耗品分类名称" prop="materialClassName"/>
      <el-table-column :align="'center'" label="消耗品名称" prop="materialName"/>
      <el-table-column :align="'center'" label="消耗品机构编码" prop="materialCode"/>
      <el-table-column :align="'center'" label="消耗品系统编码" prop="sysMaterialCode"/>
      <el-table-column :align="'center'" label="消耗品拼音码" prop="materialInput"/>
      <el-table-column :align="'center'" label="规格" prop="spec"/>
      <el-table-column :align="'center'" label="单位" prop="units">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['spec_unit']" :value="scope.row.units"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="单位名称" prop="unitsName"/>
      <el-table-column :align="'center'" label="批号" prop="batchNo"/>
      <el-table-column :align="'center'" label="生产日期" prop="produceDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.produceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="有效期" prop="expireDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.expireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="厂商名称" prop="firmName"/>
      <el-table-column :align="'center'" label="包装数量" prop="packageNum"/>
      <el-table-column :align="'center'" label="价表" prop="priceId"/>
      <el-table-column :align="'center'" label="大小包装" prop="packSize"/>
      <el-table-column :align="'center'" label="数量" prop="amount"/>
      <el-table-column :align="'center'" label="现行数量" prop="currentAmount"/>
      <el-table-column :align="'center'" label="进货价" prop="tradePrice"/>
      <el-table-column :align="'center'" label="单价" prop="itemPrice"/>
      <el-table-column :align="'center'" label="总额" prop="costs"/>
      <el-table-column :align="'center'" label="收费系数" prop="priceQuotiety"/>
      <el-table-column :align="'center'" label="开单医生" prop="orderDoctor"/>
      <el-table-column :align="'center'" label="申请科室(领取科室)" prop="applyDept"/>
      <el-table-column :align="'center'" label="申请人(领取人)" prop="applyPerson"/>
      <el-table-column :align="'center'" label="记录科室(发放科室)" prop="recordDept"/>
      <el-table-column :align="'center'" label="记录人(发放人)" prop="recordPerson"/>
      <el-table-column :align="'center'" label="领用人" prop="usePerson"/>
      <el-table-column :align="'center'" label="机构ID" prop="orgId"/>
      <el-table-column :align="'center'" label="机构名称" prop="orgName"/>
      <el-table-column :align="'center'" label="更新人名称" prop="updateByName"/>
      <el-table-column :align="'center'" label="备注" prop="remarks"/>
      <el-table-column :align="'center'" class-name="small-padding fixed-width" label="操作" width="220">
        <template #default="scope">
          <el-button
            v-hasPerm="['material:materialStockAllLog:edit']"
            type="success"
            @click="handleUpdate(scope.row)"
          >
            <template #icon>
              <i-ep-edit/>
            </template>
            修改
          </el-button>
          <el-button
            v-hasPerm="['material:materialStockAllLog:remove']"
            type="danger"
            @click="handleDelete(scope.row)"
          >
            <template #icon>
              <i-ep-delete/>
            </template>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改消耗品库存全量日志对话框 -->
    <el-dialog v-model="open" :close-on-click-modal="false" :title="title" append-to-body width="500px">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="门诊号" prop="clinicNo">
          <el-input v-model="form.clinicNo" placeholder="请输入门诊号"/>
        </el-form-item>
        <el-form-item label="住院号" prop="visitNo">
          <el-input v-model="form.visitNo" placeholder="请输入住院号"/>
        </el-form-item>
        <el-form-item label="结算号" prop="rcptNo">
          <el-input v-model="form.rcptNo" placeholder="请输入结算号"/>
        </el-form-item>
        <el-form-item label="单号" prop="documentNo">
          <el-input v-model="form.documentNo" placeholder="请输入单号"/>
        </el-form-item>
        <el-form-item label="明细id" prop="detailId">
          <el-input v-model="form.detailId" placeholder="请输入明细id"/>
        </el-form-item>
        <el-form-item label="退药明细id" prop="detailRefundId">
          <el-input v-model="form.detailRefundId" placeholder="请输入退药明细id"/>
        </el-form-item>
        <el-form-item label="1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用"
                      prop="recordType">
          <el-select v-model="form.recordType"
                     placeholder="请选择1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用">
            <el-option
              v-for="dict in dictDataMap['${dictType}']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来源类型" prop="sourceType">
          <el-select v-model="form.sourceType" placeholder="请选择来源类型">
            <el-option
              v-for="dict in dictDataMap['${dictType}']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品ID" prop="infoId">
          <el-input v-model="form.infoId" placeholder="请输入消耗品ID"/>
        </el-form-item>
        <el-form-item label="消耗品库存表id" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入消耗品库存表id"/>
        </el-form-item>
        <el-form-item label="消耗品产品类别" prop="materialStyle">
          <el-select v-model="form.materialStyle" placeholder="请选择消耗品产品类别">
            <el-option
              v-for="dict in dictDataMap['material_style']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品产品类别名称" prop="materialStyleName">
          <el-input v-model="form.materialStyleName" placeholder="请输入消耗品产品类别名称"/>
        </el-form-item>
        <el-form-item label="消耗品分类" prop="materialClass">
          <el-select v-model="form.materialClass" placeholder="请选择消耗品分类">
            <el-option
              v-for="dict in dictDataMap['bill_item_class_dict']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="消耗品分类名称" prop="materialClassName">
          <el-input v-model="form.materialClassName" placeholder="请输入消耗品分类名称"/>
        </el-form-item>
        <el-form-item label="消耗品名称" prop="materialName">
          <el-input v-model="form.materialName" placeholder="请输入消耗品名称"/>
        </el-form-item>
        <el-form-item label="消耗品机构编码" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入消耗品机构编码"/>
        </el-form-item>
        <el-form-item label="消耗品系统编码" prop="sysMaterialCode">
          <el-input v-model="form.sysMaterialCode" placeholder="请输入消耗品系统编码"/>
        </el-form-item>
        <el-form-item label="消耗品拼音码" prop="materialInput">
          <el-input v-model="form.materialInput" placeholder="请输入消耗品拼音码"/>
        </el-form-item>
        <el-form-item label="规格" prop="spec">
          <el-input v-model="form.spec" placeholder="请输入规格"/>
        </el-form-item>
        <el-form-item label="单位" prop="units">
          <el-select v-model="form.units" placeholder="请选择单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单位名称" prop="unitsName">
          <el-input v-model="form.unitsName" placeholder="请输入单位名称"/>
        </el-form-item>
        <el-form-item label="批号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入批号"/>
        </el-form-item>
        <el-form-item label="生产日期" prop="produceDate">
          <el-date-picker v-model="form.produceDate"
                          clearable
                          placeholder="请选择生产日期"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-date-picker v-model="form.expireDate"
                          clearable
                          placeholder="请选择有效期"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="厂商名称" prop="firmName">
          <el-input v-model="form.firmName" placeholder="请输入厂商名称"/>
        </el-form-item>
        <el-form-item label="包装数量" prop="packageNum">
          <el-input v-model="form.packageNum" placeholder="请输入包装数量"/>
        </el-form-item>
        <el-form-item label="价表" prop="priceId">
          <el-input v-model="form.priceId" placeholder="请输入价表"/>
        </el-form-item>
        <el-form-item label="大小包装" prop="packSize">
          <el-input v-model="form.packSize" placeholder="请输入大小包装"/>
        </el-form-item>
        <el-form-item label="数量" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入数量"/>
        </el-form-item>
        <el-form-item label="现行数量" prop="currentAmount">
          <el-input v-model="form.currentAmount" placeholder="请输入现行数量"/>
        </el-form-item>
        <el-form-item label="进货价" prop="tradePrice">
          <el-input v-model="form.tradePrice" placeholder="请输入进货价"/>
        </el-form-item>
        <el-form-item label="单价" prop="itemPrice">
          <el-input v-model="form.itemPrice" placeholder="请输入单价"/>
        </el-form-item>
        <el-form-item label="总额" prop="costs">
          <el-input v-model="form.costs" placeholder="请输入总额"/>
        </el-form-item>
        <el-form-item label="收费系数" prop="priceQuotiety">
          <el-input v-model="form.priceQuotiety" placeholder="请输入收费系数"/>
        </el-form-item>
        <el-form-item label="开单医生" prop="orderDoctor">
          <el-input v-model="form.orderDoctor" placeholder="请输入开单医生"/>
        </el-form-item>
        <el-form-item label="申请科室(领取科室)" prop="applyDept">
          <el-input v-model="form.applyDept" placeholder="请输入申请科室(领取科室)"/>
        </el-form-item>
        <el-form-item label="申请人(领取人)" prop="applyPerson">
          <el-input v-model="form.applyPerson" placeholder="请输入申请人(领取人)"/>
        </el-form-item>
        <el-form-item label="记录科室(发放科室)" prop="recordDept">
          <el-input v-model="form.recordDept" placeholder="请输入记录科室(发放科室)"/>
        </el-form-item>
        <el-form-item label="记录人(发放人)" prop="recordPerson">
          <el-input v-model="form.recordPerson" placeholder="请输入记录人(发放人)"/>
        </el-form-item>
        <el-form-item label="领用人" prop="usePerson">
          <el-input v-model="form.usePerson" placeholder="请输入领用人"/>
        </el-form-item>
        <el-form-item label="机构ID" prop="orgId">
          <el-input v-model="form.orgId" placeholder="请输入机构ID"/>
        </el-form-item>
        <el-form-item label="机构名称" prop="orgName">
          <el-input v-model="form.orgName" placeholder="请输入机构名称"/>
        </el-form-item>
        <el-form-item label="更新人名称" prop="updateByName">
          <el-input v-model="form.updateByName" placeholder="请输入更新人名称"/>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts">
export default {
  name: "MaterialStockAllLog"
}
</script>

<script lang="ts" setup>
import {
  addMaterialStockAllLog,
  delMaterialStockAllLog,
  getMaterialStockAllLog,
  listMaterialStockAllLog,
  updateMaterialStockAllLog
} from "@/api/material/materialStockAllLog";

import {useDictStoreHook} from "@/store/modules/dict";

const dictStore = useDictStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData('spec_unit', 'material_style', 'bill_item_class_dict'))

const {proxy} = getCurrentInstance() as any;

const formRef = ref();
const queryParamsRef = ref()
const materialStockAllLogList = ref([]);
const open = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const form = ref<any>({
  clinicNo: "",
  visitNo: "",
  rcptNo: "",
  documentNo: "",
  detailId: "",
  detailRefundId: "",
  recordType: "",
  sourceType: "",
  infoId: "",
  stockId: "",
  materialStyle: "",
  materialStyleName: "",
  materialClass: "",
  materialClassName: "",
  materialName: "",
  materialCode: "",
  sysMaterialCode: "",
  materialInput: "",
  spec: "",
  units: "",
  unitsName: "",
  batchNo: "",
  produceDate: "",
  expireDate: "",
  firmName: "",
  packageNum: 0,
  priceId: "",
  packSize: "",
  amount: 0,
  currentAmount: 0,
  tradePrice: 0,
  itemPrice: 0,
  costs: 0,
  priceQuotiety: 0,
  orderDoctor: "",
  applyDept: "",
  applyPerson: "",
  recordDept: "",
  recordPerson: "",
  usePerson: "",
  orgId: "",
  orgName: "",
  updateByName: "",
  remarks: ""
})
const queryParams = ref<any>({
  pageNum: 1,
  pageSize: 10,
  clinicNo: "",
  visitNo: "",
  rcptNo: "",
  documentNo: "",
  detailId: "",
  detailRefundId: "",
  recordType: "",
  sourceType: "",
  infoId: "",
  stockId: "",
  materialStyle: "",
  materialStyleName: "",
  materialClass: "",
  materialClassName: "",
  materialName: "",
  materialCode: "",
  sysMaterialCode: "",
  materialInput: "",
  spec: "",
  units: "",
  unitsName: "",
  batchNo: "",
  produceDate: "",
  expireDate: "",
  firmName: "",
  packageNum: 0,
  priceId: "",
  packSize: "",
  amount: 0,
  currentAmount: 0,
  tradePrice: 0,
  itemPrice: 0,
  costs: 0,
  priceQuotiety: 0,
  orderDoctor: "",
  applyDept: "",
  applyPerson: "",
  recordDept: "",
  recordPerson: "",
  usePerson: "",
  orgId: "",
  orgName: "",
  updateByName: "",
  remarks: ""
})
const rules = ref<any>({
  allLogId: [
    {
      required: true, message: "主键不能为空", trigger: "blur"
    }
  ],
  recordType: [
    {
      required: true,
      message: "1.门诊处方2.住院处方3.摆药4.住院退5.入库6.出库7.盘点8.科室扣减9门诊处方退10手术室用不能为空",
      trigger: "change"
    }
  ],
  infoId: [
    {
      required: true, message: "消耗品ID不能为空", trigger: "blur"
    }
  ],
  materialStyle: [
    {
      required: true, message: "消耗品产品类别不能为空", trigger: "change"
    }
  ],
  materialClass: [
    {
      required: true, message: "消耗品分类不能为空", trigger: "change"
    }
  ],
  materialName: [
    {
      required: true, message: "消耗品名称不能为空", trigger: "blur"
    }
  ],
  materialCode: [
    {
      required: true, message: "消耗品机构编码不能为空", trigger: "blur"
    }
  ],
  spec: [
    {
      required: true, message: "规格不能为空", trigger: "blur"
    }
  ],
  units: [
    {
      required: true, message: "单位不能为空", trigger: "change"
    }
  ],
  packageNum: [
    {
      required: true, message: "包装数量不能为空", trigger: "blur"
    }
  ],
  packSize: [
    {
      required: true, message: "大小包装不能为空", trigger: "blur"
    }
  ],
  amount: [
    {
      required: true, message: "数量不能为空", trigger: "blur"
    }
  ],
  itemPrice: [
    {
      required: true, message: "单价不能为空", trigger: "blur"
    }
  ],
  costs: [
    {
      required: true, message: "总额不能为空", trigger: "blur"
    }
  ],
  orgName: [
    {
      required: true, message: "机构名称不能为空", trigger: "blur"
    }
  ],
})


/** 查询消耗品库存全量日志列表 */
function getList() {
  listMaterialStockAllLog(queryParams.value).then((response: any) => {
    materialStockAllLogList.value = response.rows;
    total.value = response.total;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    allLogId: "",
    clinicNo:
      "",
    visitNo:
      "",
    rcptNo:
      "",
    documentNo:
      "",
    detailId:
      "",
    detailRefundId:
      "",
    recordType:
      "",
    sourceType:
      "",
    infoId:
      "",
    stockId:
      "",
    materialStyle:
      "",
    materialStyleName:
      "",
    materialClass:
      "",
    materialClassName:
      "",
    materialName:
      "",
    materialCode:
      "",
    sysMaterialCode:
      "",
    materialInput:
      "",
    spec:
      "",
    units:
      "",
    unitsName:
      "",
    batchNo:
      "",
    produceDate:
      "",
    expireDate:
      "",
    firmName:
      "",
    orderDoctor:
      "",
    applyDept:
      "",
    applyPerson:
      "",
    recordDept:
      "",
    recordPerson:
      "",
    usePerson:
      "",
    delFlag:
      "",
    orgId:
      "",
    orgName:
      "",
    createBy:
      "",
    createTime:
      "",
    updateBy:
      "",
    updateByName:
      "",
    updateTime:
      "",
    remarks:
      ""
  }
  nextTick(() => {
    formRef.value.resetFields()
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParamsRef.value.resetFields()
  // proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.allLogId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  if (!queryParams.value.orgId) {
    return ElMessage.error("请先选择机构")
  }
  open.value = true;
  reset();
  title.value = "添加消耗品库存全量日志";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  open.value = true;
  reset();
  const _allLogId = row.allLogId || ids.value
  getMaterialStockAllLog(_allLogId).then((response: any) => {
    form.value = response.data;
    title.value = "修改消耗品库存全量日志";
  });
}

/** 提交按钮 */
function submitForm() {
  (formRef.value as any).validate(valid => {
    if (valid) {
      if (form.value.allLogId != null) {
        updateMaterialStockAllLog(form.value).then((response: any) => {
          ElMessage.success("修改成功");
          open.value = false;
          getList();
        }).finally(() => {
        });
      } else {
        addMaterialStockAllLog(form.value).then((response: any) => {
          ElMessage.success("新增成功");
          open.value = false;
          getList();
        }).finally(() => {
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _allLogIds = row.allLogId ||
    ids.value;
  ElMessageBox.confirm('是否确认删除消耗品库存全量日志编号为"' + allLogIds + '"的数据项？',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    delMaterialStockAllLog(_allLogIds).then(() => {
      getList();
      ElMessage.success("删除成功");
    })
  }).catch(() => {
  })
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download('material/materialStockAllLog/export', {
    ...queryParams.value
  }, `materialStockAllLog_${new Date().getTime()}.xlsx`)
}

getList();
</script>
